import Markdown from "@js/markdown/markdown.js"

export function makeSummary(mat) {
  if (mat.intro) {
    return mat.intro;
  } else {
    let maxLines = 5;
    let content = mat.content;
    // 获取前三行内容
    let lines = content.split('\n');
    let ret = [];
    let n = 0;
    while (n < lines.length && ret.length < maxLines) {
      let line = lines[n];
      ret.push(line);
      n = n + 1;
    }
    if (ret.length > maxLines) {
      ret.push("...");
    }
    return ret.join("\n");
  }
}
export function makeMdSummary(mat) {
  if (mat.intro) {
    return mat.intro;
  } else {
    let maxLines = 5;
    let content = mat.content;
    // 获取前三行内容
    let lines = content.split('\n');
    let ret = [];
    let n = 0;
    while (n < lines.length && ret.length < maxLines) {
      let line = lines[n];
      ret.push(Markdown.render(line));
      n = n + 1;
    }
    if (ret.length > maxLines) {
      ret.push("...");
    }
    return ret.join("\n");
  }
}